/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myyong.test.user;

import com.mkyong.config.MongoUtil;
import com.myyong.model.Comments;
import com.myyong.model.Post;
import com.myyong.model.User;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.springframework.data.mongodb.core.MongoOperations;

/**
 *
 * @author dell
 */
public class PostSave {

    private MongoOperations mo = MongoUtil.getMongoOperations();

    public void insert(List<User> userList) {
        for (User user : userList) {
            mo.save(user);
        }
    }

    public void sinsert(Post post) {
        mo.save(post);
    }

    public static void main(String[] args) {
        PostSave ps = new PostSave();
        Post post = new Post();
        post.setAuthor("cz");

        List<Comments> commentsList = new ArrayList<>();
        for (int i = 0; i <= 100; i++) {
            Comments comment = new Comments();
            comment.setDate(Calendar.getInstance().getTime());
            comment.setReplyUser("cz");
            commentsList.add(comment);
        }
        post.setComments(commentsList);
        ps.sinsert(post);
    }
}
